<?php

/**
 * Table/NationaliteTable.php
 */

namespace RHX\Model\Table;

use Zend\Db\Adapter\Adapter;
use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\ResultSet\ResultSet;
use RHX\Model\Object\Nationalite;

class NationaliteTable extends AbstractTableGateway {

    protected $table = 'rh_nationalite';

    /**
     * Cosntructeur
     *
     * @param \Zend\Db\Adapter\Adapter $adapter
     */
    public function __construct(Adapter $adapter) {
	$this->adapter			 = $adapter;
	$this->resultSetPrototype	 = new ResultSet();
	$this->resultSetPrototype->setArrayObjectPrototype(new Nationalite($adapter));
	$this->initialize();
    }

    /**
     * Toutes les nationalités
     *
     * @param string $order
     * @return \Zend\Db\Adapter\Driver\Pdo\Result
     */
    public function getAll($order = 'libelle ASC') {
	return $this->select(function(\Zend\Db\Sql\Select $select)use($order) {
			    $select->order($order);
			});
    }

    /**
     * Nationalité
     *
     * @param type $id
     * @return Nationalite
     */
    public function get($id) {
	$row = $this->select(array('id' => $id))
		->current();
	if (!$row)
	    return null;
	return $row;
    }

}

?>
